<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .active {
     background-color: aqua 
    }
  </style>
</head>
<body>
  <div class="box">
    我是div
  </div>
  <button class="btn">切换</button>
  <script>
    var boxEl = document.querySelector(".box")

    boxEl.className = "abc"
    boxEl.classList.add("active")
    var btnEl =  document.querySelector(".btn")
    btnEl.onclick = function() {
      // if(boxEl.classList.contains("active"))
      // {
      //   boxEl.classList.remove("active")
      // } else {
      //   boxEl.classList.add("active")
      boxEl.classList.toggle("active")
      }
  </script>
</body>
</html>